VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MsComCtl.ocx"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmAPPurchaseRequest 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   8340
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   9720
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   18537.92
   ScaleMode       =   0  'User
   ScaleWidth      =   9720
   ShowInTaskbar   =   0   'False
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   285
      Left            =   0
      TabIndex        =   0
      Top             =   8055
      Width           =   9720
      _ExtentX        =   17145
      _ExtentY        =   503
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   5
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            AutoSize        =   1
            Bevel           =   0
            Object.Width           =   3918
            MinWidth        =   2
         EndProperty
         BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel5 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin ITGControls.ITGTab SSTab1 
      Height          =   4065
      Left            =   45
      TabIndex        =   14
      Top             =   45
      Width           =   9165
      _ExtentX        =   16166
      _ExtentY        =   7170
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   1
      Tab(0)ContCtrlCap(1)=   "ComunionFrames1"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      InActiveTabForeColor=   0
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   16243138
      DisabledTabForeColor=   -2147483630
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   2790
         Left            =   -75000
         TabIndex        =   20
         Top             =   315
         Width           =   9165
         _ExtentX        =   16166
         _ExtentY        =   4921
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   6
         BeginProperty Column00 
            DataField       =   "cPRNo"
            Caption         =   "Requisition No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "dDate"
            Caption         =   "Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cType"
            Caption         =   "Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cRefNo"
            Caption         =   "Reference Number"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "dNeeded"
            Caption         =   "Date Needed"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "cDept"
            Caption         =   "Department"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1349.858
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   1230.236
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   1049.953
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               ColumnWidth     =   1500.095
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
               ColumnWidth     =   1244.976
            EndProperty
            BeginProperty Column05 
               ColumnWidth     =   1980.284
            EndProperty
         EndProperty
      End
      Begin ITGControls.ComunionFrames ComunionFrames1 
         Height          =   3750
         Left            =   0
         Top             =   315
         Width           =   9165
         _ExtentX        =   16166
         _ExtentY        =   6615
         FrameColor      =   4210752
         BackColor       =   16243138
         FillColor       =   16243138
         RoundedCorner   =   0   'False
         Caption         =   "Purchase Request Information"
         Alignment       =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ThemeColor      =   5
         ColorFrom       =   16243138
         ColorTo         =   16250865
         Begin VB.CommandButton cmdPickRToDept 
            Height          =   300
            Left            =   2955
            Picture         =   "frmAPPurchaseRequest.frx":0000
            Style           =   1  'Graphical
            TabIndex        =   32
            Top             =   2235
            Visible         =   0   'False
            Width           =   315
         End
         Begin VB.CommandButton cmdPickBranch 
            Height          =   300
            Left            =   2955
            Picture         =   "frmAPPurchaseRequest.frx":014A
            Style           =   1  'Graphical
            TabIndex        =   29
            Top             =   2565
            Visible         =   0   'False
            Width           =   315
         End
         Begin VB.CommandButton cmdPickRequestedTo 
            Height          =   300
            Left            =   2970
            Picture         =   "frmAPPurchaseRequest.frx":0294
            Style           =   1  'Graphical
            TabIndex        =   26
            Top             =   1905
            Visible         =   0   'False
            Width           =   315
         End
         Begin VB.ComboBox cboPurpose 
            Height          =   315
            ItemData        =   "frmAPPurchaseRequest.frx":03DE
            Left            =   1410
            List            =   "frmAPPurchaseRequest.frx":03F4
            Style           =   2  'Dropdown List
            TabIndex        =   11
            Top             =   3000
            Width           =   6870
         End
         Begin VB.ComboBox cboType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmAPPurchaseRequest.frx":045E
            Left            =   6960
            List            =   "frmAPPurchaseRequest.frx":0471
            Style           =   2  'Dropdown List
            TabIndex        =   3
            Top             =   630
            Width           =   1335
         End
         Begin VB.Timer Timer1 
            Interval        =   300
            Left            =   3030
            Top             =   435
         End
         Begin VB.CommandButton cmdPickSO 
            Height          =   300
            Left            =   2970
            Picture         =   "frmAPPurchaseRequest.frx":04A7
            Style           =   1  'Graphical
            TabIndex        =   5
            Top             =   945
            Width           =   315
         End
         Begin VB.CommandButton cmdPickEmpCode 
            Height          =   300
            Left            =   2970
            Picture         =   "frmAPPurchaseRequest.frx":05F1
            Style           =   1  'Graphical
            TabIndex        =   8
            Top             =   1260
            Width           =   315
         End
         Begin VB.CommandButton cmdPickDeptID 
            Height          =   300
            Left            =   2970
            Picture         =   "frmAPPurchaseRequest.frx":073B
            Style           =   1  'Graphical
            TabIndex        =   10
            Top             =   1575
            Width           =   315
         End
         Begin ITGControls.ITGTextBox txtPRNo 
            Height          =   285
            Left            =   120
            TabIndex        =   1
            Top             =   630
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Requisition No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtRemarks 
            Height          =   285
            Left            =   135
            TabIndex        =   12
            Top             =   3345
            Width           =   8145
            _ExtentX        =   14155
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Remarks"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   6835
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGDateBox dtbDate 
            Height          =   285
            Left            =   4770
            TabIndex        =   2
            Tag             =   "Transaction Date"
            Top             =   630
            Width           =   1395
            _ExtentX        =   2461
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
            Mandatory       =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtRefNo 
            Height          =   285
            Left            =   135
            TabIndex        =   4
            Top             =   945
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "Reference No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
         End
         Begin ITGControls.ITGDateBox dtbNeeded 
            Height          =   285
            Left            =   4770
            TabIndex        =   6
            Tag             =   "Date Needed"
            Top             =   945
            Width           =   1395
            _ExtentX        =   2461
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtType 
            Height          =   285
            Left            =   6330
            TabIndex        =   15
            Tag             =   "cboType"
            Top             =   630
            Width           =   1710
            _ExtentX        =   2805
            _ExtentY        =   503
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1000
            TextBoxWidth    =   650
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtRequestedBy 
            Height          =   285
            Left            =   135
            TabIndex        =   7
            Top             =   1260
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Requested by"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtDepartment 
            Height          =   285
            Left            =   135
            TabIndex        =   9
            Top             =   1590
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Department"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtDeptDesc 
            Height          =   285
            Left            =   3285
            TabIndex        =   16
            TabStop         =   0   'False
            Top             =   1575
            Width           =   4995
            _ExtentX        =   8705
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4935
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtEmpName 
            Height          =   285
            Left            =   3285
            TabIndex        =   17
            TabStop         =   0   'False
            Top             =   1260
            Width           =   4995
            _ExtentX        =   8705
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4935
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtPurpose 
            Height          =   285
            Left            =   135
            TabIndex        =   13
            Top             =   2970
            Width           =   5490
            _ExtentX        =   9472
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Purpose"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   4180
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGTextBox txtRequestedTo 
            Height          =   285
            Left            =   135
            TabIndex        =   27
            Top             =   1905
            Visible         =   0   'False
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Requested to"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtRequestedToName 
            Height          =   285
            Left            =   3285
            TabIndex        =   28
            TabStop         =   0   'False
            Top             =   1905
            Visible         =   0   'False
            Width           =   4995
            _ExtentX        =   8705
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4935
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtBranch 
            Height          =   285
            Left            =   120
            TabIndex        =   30
            Top             =   2565
            Visible         =   0   'False
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Branch"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtBranchName 
            Height          =   285
            Left            =   3270
            TabIndex        =   31
            TabStop         =   0   'False
            Top             =   2565
            Visible         =   0   'False
            Width           =   4995
            _ExtentX        =   8705
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4935
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtRToDept 
            Height          =   285
            Left            =   120
            TabIndex        =   33
            Top             =   2235
            Visible         =   0   'False
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Department"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtRToDeptName 
            Height          =   285
            Left            =   3270
            TabIndex        =   34
            TabStop         =   0   'False
            Top             =   2235
            Visible         =   0   'False
            Width           =   4995
            _ExtentX        =   8705
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4935
            Enabled         =   0   'False
         End
         Begin VB.Label Label2 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "Date Needed"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   3705
            TabIndex        =   19
            Top             =   945
            Width           =   1035
         End
         Begin VB.Label Label1 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "Date"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   4245
            TabIndex        =   18
            Top             =   630
            Width           =   435
         End
      End
   End
   Begin ITGControls.ComunionFrames ComunionFrames2 
      Height          =   3540
      Left            =   45
      Top             =   4170
      Width           =   9165
      _ExtentX        =   16166
      _ExtentY        =   6244
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Details"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin VB.TextBox txtLongDesc 
         Appearance      =   0  'Flat
         DataField       =   "cLongDesc"
         Height          =   1215
         Left            =   4155
         MaxLength       =   1000
         MultiLine       =   -1  'True
         TabIndex        =   24
         Top             =   975
         Visible         =   0   'False
         Width           =   4065
      End
      Begin VB.ComboBox cboUnit 
         Height          =   315
         ItemData        =   "frmAPPurchaseRequest.frx":0885
         Left            =   285
         List            =   "frmAPPurchaseRequest.frx":0892
         Style           =   2  'Dropdown List
         TabIndex        =   23
         Top             =   1560
         Visible         =   0   'False
         Width           =   1035
      End
      Begin VB.ComboBox cboPRType 
         Height          =   315
         ItemData        =   "frmAPPurchaseRequest.frx":08AC
         Left            =   285
         List            =   "frmAPPurchaseRequest.frx":08B3
         Style           =   2  'Dropdown List
         TabIndex        =   22
         Top             =   1890
         Visible         =   0   'False
         Width           =   1035
      End
      Begin VB.ComboBox cboPR 
         Height          =   315
         ItemData        =   "frmAPPurchaseRequest.frx":08C1
         Left            =   285
         List            =   "frmAPPurchaseRequest.frx":08CB
         Style           =   2  'Dropdown List
         TabIndex        =   21
         Top             =   2220
         Visible         =   0   'False
         Width           =   1035
      End
      Begin MSDataGridLib.DataGrid dtgPR 
         Height          =   3120
         Left            =   0
         TabIndex        =   25
         Top             =   420
         Width           =   9165
         _ExtentX        =   16166
         _ExtentY        =   5503
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         AllowDelete     =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   11
         BeginProperty Column00 
            DataField       =   "cType"
            Caption         =   "Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cItemType"
            Caption         =   "Product Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cDesc"
            Caption         =   "Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "nQty"
            Caption         =   "Quantity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "dLastOrdered"
            Caption         =   "Last Ordered"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "nBalance"
            Caption         =   "Balance"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column08 
            DataField       =   "nConsumed"
            Caption         =   "Consumed"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column09 
            DataField       =   "nApproved"
            Caption         =   "Quantity Approved"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column10 
            DataField       =   "cBarcodeID"
            Caption         =   "Barcode ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   975.118
            EndProperty
            BeginProperty Column01 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1200.189
            EndProperty
            BeginProperty Column02 
               Button          =   -1  'True
               ColumnWidth     =   1409.953
            EndProperty
            BeginProperty Column03 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   2684.977
            EndProperty
            BeginProperty Column04 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   675.213
            EndProperty
            BeginProperty Column05 
            EndProperty
            BeginProperty Column06 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1094.74
            EndProperty
            BeginProperty Column07 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1349.858
            EndProperty
            BeginProperty Column08 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column09 
               Object.Visible         =   0   'False
               ColumnWidth     =   1470.047
            EndProperty
            BeginProperty Column10 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1154.835
            EndProperty
         EndProperty
      End
   End
End
Attribute VB_Name = "frmAPPurchaseRequest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.09.23

Option Explicit

'Object variables




Private oPrint As New clsPrinting


'ADO Connection variables

Private connHeader As ADODB.Connection
Private connDetail As ADODB.Connection

'Recordset variables
Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1
Private rsDetail As ADODB.Recordset

'Form mode enumeration
Enum eAPPRMode
    Normal
    AddNewEdit
    Find
    ShowForm
End Enum
Public Mode As eAPPRMode

'Other declarations
Public dtgName As String
Public sBit As String
Private vBM As Variant 'Recordset bookmark variable

Private lSystemGenerated As Boolean
Public strNo As String

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean

Private Sub cboPR_Click()
    If dtgPR.Col = 1 Then
        rsDetail!cItemType = cboPR
    End If
End Sub

Private Sub cboPR_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        If dtgPR.Col = 1 Then
            rsDetail!cItemType = cboPR
            cboPR.Visible = False
            dtgPR.Col = 2
            dtgPR.SetFocus
        End If
    ElseIf KeyCode = vbKeyEscape Then
        cboPR.Visible = False
    End If
End Sub

Private Sub cboPR_LostFocus()
    cboPR.Visible = False
End Sub

Private Sub cboPRType_Click()
    If dtgPR.Col = 0 Then
        rsDetail!cType = cboPRType
    ElseIf dtgPR.Col = 4 Then
        rsDetail!cUnit = cboPRType
    End If
End Sub

Private Sub cboPRType_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        If dtgPR.Col = 0 Then
            rsDetail!cType = cboPRType
            cboPRType.Visible = False
            dtgPR.Col = 1
            dtgPR.SetFocus
        End If
    ElseIf KeyCode = vbKeyEscape Then
        cboPRType.Visible = False
    End If
End Sub

Private Sub cboPRType_LostFocus()
    cboPRType.Visible = False
End Sub

Private Sub cboType_Click()
    txtType = Trim(cboType)
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(cboType) = "For stock" Then
        txtRefNo.TabStop = False
        cmdPickSO.TabStop = False
        txtRefNo.Locked = True
        cmdPickSO.Enabled = False
    Else
        txtRefNo.TabStop = True
        cmdPickSO.TabStop = True
        txtRefNo.Locked = True
        cmdPickSO.Enabled = True
    End If
    ClearDetails
End Sub

Private Sub cboType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboUnit_Change()
    rsDetail!cUnit = cboUnit
    rsDetail!nFactor = GetValueFrTable("nFactor", "Item_Unit", "cItemNo = '" & Trim(rsDetail!cItemNo) & "' and cUnit = '" & Trim(rsDetail!cUnit) & "'")
End Sub

Private Sub cboUnit_Click()
    rsDetail!cUnit = cboUnit
    rsDetail!nFactor = GetValueFrTable("nFactor", "Item_Unit", "cItemNo = '" & Trim(rsDetail!cItemNo) & "' and cUnit = '" & Trim(rsDetail!cUnit) & "'")
End Sub

Private Sub cboUnit_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        If dtgPR.Col = 4 Then
            rsDetail!cUnit = cboUnit
            rsDetail!nFactor = GetValueFrTable("nFactor", "Item_Unit", "cItemNo = '" & Trim(rsDetail!cItemNo) & "' and cUnit = '" & Trim(rsDetail!cUnit) & "'")
            dtgPR.Col = 5
            dtgPR.SetFocus
            cboUnit.Visible = False
        End If
    ElseIf KeyCode = vbKeyEscape Then
        cboUnit.Visible = False
    End If
End Sub

Private Sub cboUnit_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If dtgPR.Col = 4 Then
            rsDetail!cUnit = cboUnit
            rsDetail!nFactor = GetValueFrTable("nFactor", "Item_Unit", "cUnit = '" & Trim(rsDetail!cItemNo) & "' and cUnit = '" & Trim(rsDetail!cUnit) & "'")
            dtgPR.Col = 5
            dtgPR.SetFocus
        End If
    ElseIf KeyAscii = vbKeyEscape Then
    End If
    cboUnit.Visible = False
End Sub

Private Sub cboUnit_LostFocus()
    cboUnit.Visible = False
End Sub

Private Sub cmdPickBranch_Click()
If lPickListActive Then Exit Sub
    sFilterString = Trim(txtBranch)
    With frmITGPicker
        .zType = QCustomer
        .Show vbModal
        txtBranch = .zCode
        txtBranchName = .zName
    End With
    If Trim(txtBranchName) <> "" Then txtPurpose.SetFocus
End Sub

Private Sub cmdPickDeptID_Click()
    If lPickListActive Then Exit Sub
    frmITGPicker.zType = QSecDepartment
    frmITGPicker.Show vbModal
    txtDepartment = frmITGPicker.zCode
    txtDeptDesc = frmITGPicker.zName
    If Trim(txtDeptDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickEmpCode_Click()
    If lPickListActive Then Exit Sub
    frmITGPicker.zType = QEmployee
    frmITGPicker.Show vbModal
    txtRequestedBy = frmITGPicker.zCode
    txtEmpName = frmITGPicker.zName
    txtDepartment = GetValueFrTable("cDept", "EMPLOYEE", "cEmpCode = '" & Trim(txtRequestedBy.Text) & "'")
    If Trim(txtEmpName) <> "" Then txtPurpose.SetFocus
End Sub

Private Sub cmdPickRequestedTo_Click()
If lPickListActive Then Exit Sub
    frmITGPicker.zType = QEmployee
    frmITGPicker.Show vbModal
    txtRequestedTo = frmITGPicker.zCode
    txtRequestedToName = frmITGPicker.zName
    txtDepartment = GetValueFrTable("cDept", "EMPLOYEE", "cEmpCode = '" & Trim(txtRequestedBy.Text) & "'")
    If Trim(txtRequestedToName) <> "" Then txtBranch.SetFocus
End Sub

Private Sub cmdPickRToDept_Click()
If lPickListActive Then Exit Sub
    frmITGPicker.zType = QSecDepartment
    frmITGPicker.Show vbModal
    txtRToDept = frmITGPicker.zCode
    txtRToDeptName = frmITGPicker.zName
    If Trim(txtRToDeptName) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickSO_Click()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(cboType) = "" Then
        MsgBox "Please select transaction type.", vbInformation, "ComUnion"
        cboType.SetFocus
        Exit Sub
    End If
    If Trim(cboType) = "For stock" Then Exit Sub
    If Trim(cboType) = "From SO" Then
        frmARDRList.mDRType = APSOForBuyOut
    ElseIf Trim(cboType) = "Production" Then
        frmARDRList.mDRType = APPOForBuyOut
    ElseIf Trim(cboType) = "From RS" Then
        frmARDRList.mDRType = RequestForPR
    End If
    frmARDRList.Show vbModal
    'Me.txtRefNo = frmARDRList.txtCode
    If Trim(txtRefNo) <> "" Then
        SendKeys "{Tab}"
    End If
End Sub

Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
    SortGrid dtgList, ColIndex, rsHeader
End Sub

Private Sub dtgPR_AfterColUpdate(ByVal ColIndex As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 2
            If dtgPR.Columns(0).Text <> "Existing" Then Exit Sub
            If dtgPR.Columns(1).Text = "" Then Exit Sub
            If Trim(dtgPR.Columns(1).Text) = "Trade" Then
                If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgPR.Columns(2).Value) & "'") <> "" Then
                    GetInitialItemValues rsDetail
                    dtgPR.Col = 5
                    dtgPR.Columns(5).Value = 0
                    rsDetail!nFactor = 1
                End If
            ElseIf Trim(dtgPR.Columns(1).Text) = "Asset" Then
                If GetValueFrTable("cAssetNo", "ASSET", "cAssetNo = '" & Trim(dtgPR.Columns(2).Value) & "'") <> "" Then
                    dtgPR.Col = 5
                    dtgPR.Columns(5).Value = 0
                End If
            ElseIf Trim(dtgPR.Columns(1).Text) = "Supply" Then
                If GetValueFrTable("cSupplyNo", "SUPPLY", "cSupplyNo = '" & Trim(dtgPR.Columns(2).Value) & "'") <> "" Then
                    dtgPR.Col = 5
                    dtgPR.Columns(5).Value = 0
                End If
            End If
    End Select
End Sub

Private Sub dtgPR_ButtonClick(ByVal ColIndex As Integer)
'If Mode <> AddNewEdit Then Exit Sub
If ColIndex = 3 Then
    If Mode <> Find Then
        Call MoveText(txtLongDesc, dtgPR, dtgPR.Columns(3))
        txtLongDesc = rsDetail!cLongDesc & ""
    End If
End If
If Mode = AddNewEdit Then 'Exit Sub
    Select Case ColIndex
        Case 0
            Call MoveCombo(cboPRType, dtgPR, dtgPR.Columns(0))
            ComboLoadValue cboPRType, Trim(dtgPR.Columns(0).Text)
        Case 1
            Call MoveCombo(cboPR, dtgPR, dtgPR.Columns(1))
            ComboLoadValue cboPR, Trim(dtgPR.Columns(1).Text)
        Case 2
            If dtgPR.Columns(0).Text <> "Existing" Then Exit Sub
            If dtgPR.Columns(1).Text = "" Then Exit Sub
            If dtgPR.Columns(1).Text = "Trade" Then
                If lPickListActive Then Exit Sub
                sFilterString = Trim(dtgPR.Columns(2).Text)
                frmITGPicker.zType = QProduct
                'frmITGPicker.sPCCode = sDivision
                frmITGPicker.Show vbModal
                rsDetail!cItemNo = Trim(frmITGPicker.zCode) & ""
                rsDetail!cBarcodeID = Trim(frmITGPicker.zPart) & "" 'GetValueFrTable("cItemNo", "ITEM", "cPartNo = '" & Trim(frmITGPicker.zPart) & "'")
                rsDetail!cDesc = Trim(frmITGPicker.zName) & ""
                If (Trim(frmITGPicker.zName) & "") <> "" Then
                    GetInitialItemValues rsDetail
                    dtgPR.Col = 4
                    dtgPR.Columns(5).Value = 0
                    rsDetail!nFactor = IIf(GetValueFrTable("nFactor", "ITEM_Unit", "cItemNo = '" & Trim(rsDetail!cItemNo) & "' and cUnit = '" & Trim(rsDetail!cUnit) & "'"), 1, GetValueFrTable("nFactor", "ITEM_Unit", "cItemNo = '" & Trim(rsDetail!cItemNo) & "' and cUnit = '" & Trim(rsDetail!cUnit) & "'"))
                End If
            ElseIf dtgPR.Columns(1).Text = "Asset" Then
                If lPickListActive Then Exit Sub
                sFilterString = Trim(dtgPR.Columns(2).Text)
                frmITGPicker.zType = QFixedAsset
                'frmITGPicker.sPCCode = sDivision
                frmITGPicker.Show vbModal
                rsDetail!cItemNo = Trim(frmITGPicker.zCode) & ""
                rsDetail!cDesc = Trim(frmITGPicker.zName) & ""
                If (Trim(frmITGPicker.zName) & "") <> "" Then
                    GetInitialAssetValues rsDetail
                    dtgPR.Col = 4
                    dtgPR.Columns(5).Value = 0
                End If
            ElseIf dtgPR.Columns(1).Text = "Supply" Then
                If lPickListActive Then Exit Sub
                sFilterString = Trim(dtgPR.Columns(2).Text)
                frmITGPicker.zType = QSupply
                'frmITGPicker.sPCCode = sDivision
                frmITGPicker.Show vbModal
                rsDetail!cItemNo = Trim(frmITGPicker.zCode) & ""
                If (Trim(frmITGPicker.zName) & "") <> "" Then
                    GetInitialSupplyValues rsDetail
                    dtgPR.Col = 4
                    dtgPR.Columns(5).Value = 0
                End If
            End If
            
            Call GetLastOrderd
            Call GetBalance
            Call GetConsumed
            
        Case 4
            Call LoadComboValues(cboUnit, "cUnit", "Item_Unit", "WHERE cCompanyID = '" & COID & "' and cItemNo = '" & Trim(rsDetail!cItemNo) & "'")
            Call MoveCombo(cboUnit, dtgPR, dtgPR.Columns(4))
            ComboLoadValue cboUnit, Trim(dtgPR.Columns(4).Text)
    End Select
End If
End Sub

'Set the datagrid as active control
Private Sub dtgPR_Click()
    If Mode = AddNewEdit Then dtgName = dtgPR.Name
End Sub

Private Sub dtgPR_Error(ByVal DataError As Integer, Response As Integer)
    Response = 0
End Sub

Private Sub dtgPR_GotFocus()
    dtgName = dtgPR.Name
End Sub

Private Sub dtgPR_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    End If
End Sub

Private Sub dtgPR_KeyPress(KeyAscii As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
    
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    If KeyAscii = 13 Then
        Select Case dtgPR.Col
            Case 0
                If Not cboPRType.Visible Then dtgPR_ButtonClick (0)
            Case 1
                If Not cboPR.Visible Then dtgPR_ButtonClick (1)
            Case 2
                If dtgPR.Columns(0).Text <> "Existing" Then Exit Sub
                If dtgPR.Columns(1).Text = "" Then Exit Sub
                If dtgPR.Columns(1).Text = "Trade" Then
                    If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgPR.Columns(2).Value) & "'") = "" Then
                        If Trim(dtgPR.Columns(1).Text) = "Trade" Then dtgPR_ButtonClick (2)                      'use button click
                    End If
                ElseIf dtgPR.Columns(1).Text = "Asset" Then
                    If GetValueFrTable("cAssetNo", "ASSET", "cAssetNo = '" & Trim(dtgPR.Columns(2).Value) & "'") = "" Then
                        If Trim(dtgPR.Columns(1).Text) = "Asset" Then dtgPR_ButtonClick (2)                      'use button click
                    End If
                ElseIf dtgPR.Columns(1).Text = "Supply" Then
                    If GetValueFrTable("cSupplyNo", "SUPPLY", "cSupplyNo = '" & Trim(dtgPR.Columns(2).Value) & "'") = "" Then
                        If Trim(dtgPR.Columns(1).Text) = "Supply" Then dtgPR_ButtonClick (2)                      'use button click
                    End If
                End If
            'Case 4
            '    dtgPR.LeftCol = 5
            Case 5
                TBNewLine
                dtgPR.LeftCol = 0
            Case Else
                SendKeys "{Tab}"
        End Select
    Else: KeyAscii = Asc(UCase(Chr(KeyAscii)))       'All Upper Case String
    End If
End Sub

'Right click menu popup
Private Sub dtgPR_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgPR.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub dtgPR_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
On Error Resume Next
    If Mode <> AddNewEdit Then Exit Sub
    
    If Trim(dtgPR.Columns(0).Text) = "New" Then
        dtgPR.Columns(3).Locked = False
        dtgPR.Columns(4).Locked = False
    Else
        dtgPR.Columns(3).Locked = True
        dtgPR.Columns(4).Locked = True
    End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

'Set Your Object
Private Sub Form_Load()

    Set FrmName = Me
    FormSetup

    AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'AP01'")
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset
    
    Call ColumnVisible("Barcode ID", dtgPR)
    
    FormLocking True
    FormSearch True
    SearchObj True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    Mode = Find
    txtPRNo.Locked = False
    
    SetVisibleEnable
    
End Sub

'Activate your Toolbar Mode
Private Sub Form_Activate()
    TBBitReload
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If

    CloseMenuTab ITGLedgerMain
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False

    
    
    
    
    Set oPrint = Nothing
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set connHeader = Nothing
    Set connDetail = Nothing

    Set frmAPPurchaseRequest = Nothing

    lCloseWindow = True
    
'    'oForm(Me.Tag).Mode = 1
'    'oForm(Me.Tag).Tag = Me.Tag
End Sub

'Add new record to the recordset
Public Sub TBNew()

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    txtPRNo.BackColor = &HE0FFFF
    Mode = AddNewEdit

    If rsHeader.State <> adStateOpen Then
        OpenNewConnection connHeader
        OpenNewConnection connDetail
        OpenRecordsetWithCN rsDetail, "*", "REQUISITION_T", connDetail, "WHERE 1 = 0"
        OpenRecordsetWithCN rsHeader, "*", "REQUISITION", connHeader, "WHERE 1 = 0"
        SetDataSource
        SetDataField
    Else
        vBM = rsHeader.Bookmark
    End If
    
    rsHeader.AddNew
    rsHeader!cCompanyID = COID
    rsHeader!dDate = Date
'    rsHeader!cRequestedBy = GetValueFrTable("LastName + ', ' + FirstName + ' ' + MI", "SEC_USER", "UserID = '" & sUserName & "'", True)
    GetUser txtRequestedBy, txtEmpName
    
    'Automatic Approval
    'rsHeader!lApproved = True
    
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtRefNo.Locked = True
    SSTab1.ActiveTab = 0
    txtPRNo.SetFocus

    rsHeader!cType = "For stock"
    
    'system generated number
    lSystemGenerated = GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'AUTO_NUMBER_PR' ")
    If lSystemGenerated Then rsHeader!cPRNo = GetAutoCtrlNo(rsHeader, "AUTO_NUMBER_PR", "REQUISITION", "cPRNo")

End Sub

'Undo all changes to the recordset
Public Sub TBUndoAll()
On Error GoTo ErrorHandler

    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    rsDetail.CancelBatch adAffectAll
    
    UnbindControls
    
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , lACPost, lACCancel, , , True, True, lACPrint, True
    Else
        RSZero
        Mode = Find
    End If

    sbRS.Panels(2) = ""
    
    SetDataSource
    SetDataField

ErrorHandler:

    cboPR.Visible = False
    cboPRType.Visible = False
    
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoAll
    End If

End Sub

'Undo changes on the current record
Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler

    GetChild
    If rsHeader.Status = adRecNew Then
        rsDetail.CancelBatch adAffectAll
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
        rsDetail.CancelBatch adAffectAll
    End If
   
    If rsHeader.RecordCount = 0 Then RSZero
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoCurrent
    End If

End Sub

'Save all changes

Public Sub TBSave()
Dim OKUpdate As Boolean
On Error GoTo ErrHandler

    'Audit Trail
    lBoolean = False
    If rsHeader.Status = adRecNew Then lBoolean = True
    
    If Not MandatoryOK Then Exit Sub
    
    'System generated number
    If rsHeader.Status = adRecNew Then
    
        If lSystemGenerated Then
            If ChkCtrlNo(rsHeader, "AUTO_NUMBER_PR", "REQUISITION", "cPRNo", rsHeader!cPRNo) <> rsHeader!cPRNo Then
                GetChild
                
                rsHeader!cPRNo = strNo
                
                If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
                Do Until rsDetail.EOF
                    rsDetail!cPRNo = strNo
                    rsDetail.MoveNext
                Loop
                
                GetChild
            End If
        End If
    End If
    '----------------------
    
    OKUpdate = False
    cn.BeginTrans
    connHeader.BeginTrans
    connDetail.BeginTrans
    
    rsHeader.UpdateBatch adAffectAll
    rsDetail.UpdateBatch adAffectAll
    
    cn.CommitTrans
    connHeader.CommitTrans
    connDetail.CommitTrans
    OKUpdate = True
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , lACPost, lACCancel, , , True, True, lACPrint, True
    Mode = Normal
    
    'Audit trail
    UpdateLogFile "Purchase Request", Trim(txtPRNo), IIf(lBoolean, "Inserted", "Updated")
    
    'Reminder
'    UpdateReminders Trim(txtPRNo), "Purchase Request " & Trim(txtPRNo) & "for Approval", "For Approval"
    
    'For Notification
    
    
    'update system generated number
    If lBoolean Then
        If lSystemGenerated And strNo = rsHeader!cPRNo Then UpdateControlNo strNo, rsHeader!cPRNo, "AUTO_NUMBER_PR"
    End If
    '----------------------
    
    MsgBox "Record/s successfully saved.", vbInformation, "ComUnion"
    sbRS.Panels(2) = ""
    
    
ErrHandler:
    
    cboPR.Visible = False
    cboPRType.Visible = False
    
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, "ComUnion"
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        rsDetail.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , lACPost, lACCancel, , , True, True, lACPrint, True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else
            RSZero
        End If
    End If
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, "ComUnion"
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If
    
End Sub

'Sets the form & recorset to add/edit mode
Public Sub TBEdit()
    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Edit is not allowed.", vbExclamation, "ComUnion"
        Exit Sub
    ElseIf rsHeader!lApproved Then
        MsgBox "Transaction was already approved. Edit is not allowed.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtRefNo.Locked = True
    txtPRNo.Locked = True
    SSTab1.ActiveTab = 0
    dtbDate.SetFocus
    vBM = rsHeader.Bookmark
End Sub

'Delete record
Public Sub TBDelete()
On Error GoTo ErrorHandler

    sID = Trim(txtPRNo)
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Deletion is not allowed.", vbExclamation, "ComUnion"
        Exit Sub
    ElseIf rsHeader!lApproved Then
        MsgBox "Transaction was already approved. Deletion is not allowed.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub

    GetChild
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.RecordCount = 0
            rsDetail.Delete adAffectCurrent
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Loop
    End If
    
    'Audit trail
    UpdateLogFile "Purchase Request", Trim(txtPRNo), "Deleted"

    rsHeader.Delete adAffectCurrent
    
    rsDetail.UpdateBatch adAffectAll
    rsHeader.UpdateBatch adAffectAll
    
    TBPrevRec

    Mode = Normal

    If rsHeader.RecordCount = 0 Then
        RSZero
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        cn.Execute "DELETE REQUISITION_T WHERE cPRNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        cn.Execute "DELETE REQUISITION WHERE cPRNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        Resume Next
    End If

End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    Mode = Normal
    txtPRNo.Locked = True
    frmITGSearch.Show 'vbModal
End Sub

'Search using the recordset primary key
Public Sub TBFindPrimary()
Dim sTemp As String
If Mode = Find Then
    FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
            
    OpenNewConnection connHeader
    OpenNewConnection connDetail
    
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset

    sTemp = Trim$(GetSearchString)
    If sTemp = "ERROR" Then
        MsgBox "Only Allows A - Z, 0 - 9, '.', ',' and %(wildcard)", vbExclamation, ""
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
        txtPRNo.Locked = False
        txtPRNo.SetFocus
        Exit Sub
    End If
         
    OpenRecordsetWithCN rsHeader, "*", "REQUISITION", connHeader, IIf(sTemp = "", "", " WHERE " & sTemp)
    'OpenRecordsetWithCN rsDetail, "*", "REQUISITION_T", connDetail
                  
    OpenRecordsetWithCN rsDetail, "*", "REQUISITION_T", connDetail, IIf(sTemp = "", "", " WHERE cPRNo IN (SELECT cPRNo FROM REQUISITION WHERE " & sTemp & ")")
        
    Set FrmName = Me
    FormLocking True

    If rsHeader.RecordCount = 0 Then
        FormWaitHide
        MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
        RSZero
        FormSearch True
        SearchObj True
        Mode = Find
        Exit Sub
    End If
    SetDataSource
    SetDataField
    txtPRNo.BackColor = &HE0FFFF
    Mode = Normal
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , lACPost, lACCancel, , , True, True, lACPrint, True

    FormWaitHide
Else
    RSZero
    FormSearch True
    SearchObj True
    Mode = Find
   
End If

End Sub

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
    dtgName = dtgPR.Name
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Move first
Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader

End Sub

'Move previuos
Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader

End Sub

'Move next
Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader

End Sub

'Move last
Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader
    
End Sub

'Add new line to the detail recordset
Public Sub TBNewLine()
    
    If rsHeader!cPRNo = "" Then Exit Sub
    
    If dtgName = "dtgPR" Then
        rsDetail.AddNew
        rsDetail!cCompanyID = COID
        rsDetail!cPRNo = Trim(rsHeader!cPRNo)
        rsDetail!cType = "Existing"
        GetChild
        If rsDetail.RecordCount <> 0 Then rsDetail.MoveLast
        dtgPR.Col = 1
        dtgPR.Columns(1).Value = ""
        dtgPR.SetFocus
    End If
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

End Sub

'Delete line in the detail recordset
Public Sub TBDeleteLine()
On Error GoTo ErrorHandler

    If dtgName = dtgPR.Name Then
        If rsDetail.RecordCount = 0 Then Exit Sub
        vBookMark = dtgPR.Bookmark
        GetChild
        dtgPR.Bookmark = vBookMark
        rsDetail.Delete adAffectCurrent
    End If
    GetChild

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo All
Public Sub TBUndoLineAll()
On Error GoTo ErrorHandler

    MsgBox "Unavailable on " & Me.Name

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo current line
Public Sub TBUndoLineCurrent()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Post current record
Public Sub TBPostRecord()
    'MsgBox "Unavailable on " & Me.Name
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Approval is not allowed", vbExclamation, "ComUnion"
        Exit Sub
    End If
    
    If rsHeader!lApproved = True Then
        MsgBox "Transaction was already approved.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to approve this record?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub

    'Audit trail
    UpdateLogFile "Purchase Request", Trim(txtPRNo), "Approved"
    
    rsHeader!lApproved = True
    rsHeader!cApprovedBy = sUserName
    rsHeader.UpdateBatch adAffectAll
    
    sbRS.Panels(5) = "APPROVED"
    Mode = Normal
    
    

TheSource:
    If err.Number = -2147217885 Then
        Resume Next
    End If
End Sub

'Cancel current record
Public Sub TBCancelRecord()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled.", vbExclamation, "ComUnion"
        Exit Sub
    ElseIf rsHeader!lApproved Then
        MsgBox "Transaction was already approved. Cancel is not allowed.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to cancel this record?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub
    
    'Audit trail
    UpdateLogFile "Purchase Request", Trim(txtPRNo), "Cancelled"

    cn.Execute ("UPDATE REQUISITION SET lCancelled = 1 WHERE cPRNo = '" & Trim(txtPRNo) & "' AND cCompanyID = '" & COID & "'")
    
    sbRS.Panels(5) = "CANCELLED"
    Mode = Normal
    
    rsHeader!lCancelled = True
    rsHeader.UpdateBatch adAffectAll

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Print
Public Sub TBPrintRecord()
    cModule = "Purchase_Requisition"
    oPrint.PrintReceipt Trim(txtPRNo)
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader
    Set dtgPR.DataSource = rsDetail
    Set txtLongDesc.DataSource = rsDetail
    
End Sub

'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtPRNo.DataField = !cPRNo
        dtbDate.DataField = !dDate
        txtType.DataField = !cType
        txtRefNo.DataField = !cRefNo
        dtbNeeded.DataField = !dNeeded
        txtRequestedBy.DataField = !cRequestedBy
        txtDepartment.DataField = !cDepartment
        txtPurpose.DataField = !cPurpose
        txtRemarks.DataField = !cRemarks
        txtRequestedTo.DataField = !cRequestedTo
        txtBranch.DataField = !cBranch
        txtRToDept.DataField = !cReqToDept
    End With
End Sub

Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler

    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        'Status bar setup
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount

        If rsHeader.Status <> adRecNew Then
            txtPRNo.Locked = True
        Else
            txtPRNo.Locked = False
        End If

        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else
            sbRS.Panels(2) = ""
        End If
        
        GetChild
        
        If rsHeader!lCancelled = True Then
            sbRS.Panels(5) = "CANCELLED"
        ElseIf rsHeader!lApproved Then
            sbRS.Panels(5) = "APPROVED"
        Else
            sbRS.Panels(5) = ""
        End If
    Else
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtPRNo.Locked = False
    End If

    If Mode = AddNewEdit Then
        dtgPR.Refresh
    End If

ErrorHandler:
    'Err.Number -2147217885
    'Description - Row handle referred to a deleted row or a row marked for deletion.
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Private Sub Timer1_Timer()
    If Mode = AddNewEdit Then
        SSTab1.TabEnabled(1) = False
    Else
        SSTab1.TabEnabled(1) = True
    End If
End Sub

Private Sub txtBranch_LabelClick()
    txtBranch = ""
    txtBranchName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtBranch) & "'")
End Sub



Private Sub txtPRNo_LostFocus()
    'Does Code Already Exist
    If Mode = AddNewEdit Then
        If Trim(txtPRNo) = "" Then
            MsgBox "Empty primary input.", vbInformation, "ComUnion"
            If FrmName.Name <> Me.Name Then PreviousTab frmComUnionMenuTab
            txtPRNo.SetFocus
        Else
            If rsHeader.Status <> adRecNew Then Exit Sub
            txtPRNo = Trim(txtPRNo)
            If IDExisting(rsHeader, "cPRNo", "REQUISITION", Trim(rsHeader!cPRNo)) Then
                MsgBox "Requisition No. already exist.", vbInformation, "ComUnion"
                If FrmName.Name <> Me.Name Then PreviousTab frmComUnionMenuTab
                txtPRNo.SetFocus
            End If
        End If
    End If
End Sub

'Check if all mandatory fields are complete
Function MandatoryOK() As Boolean
    
    MandatoryOK = True

    If Trim(txtPRNo) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Requisition Number' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        txtPRNo.SetFocus
        Exit Function
    End If
    
    If rsHeader.Status = adRecNew And lSystemGenerated = False Then
        If IDExisting(rsHeader, "cPRNo", "REQUISITION", Trim(rsHeader!cPRNo)) Then
            MandatoryOK = False
            MsgBox "Requisition No. already exist.", vbInformation, "ComUnion"
            txtPRNo.SetFocus
            Exit Function
        End If
    End If

    'Required fields
    If Trim(dtbDate.Text) = "__/__/____" Then
        MandatoryOK = False
        MsgBox "Field 'Transaction Date' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        dtbDate.SetFocus
        Exit Function
    ElseIf Trim(txtType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Type' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        cboType.SetFocus
        Exit Function
    ElseIf Trim(cboType) = "From SO" Then
        If Trim(txtRefNo) = "" Then
            MandatoryOK = False
            MsgBox "Field 'Reference No.' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
            txtRefNo.SetFocus
            Exit Function
        End If
    ElseIf Trim(txtRequestedBy) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Requested by' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        txtRequestedBy.SetFocus
        Exit Function
    End If
    
    GetChild
    
    'Transaction without details
    If rsDetail.RecordCount = 0 Then
        MandatoryOK = False
        MsgBox "Cannot save transaction without details.", vbInformation, "ComUnion"
        dtgPR.SetFocus
        Exit Function
    End If
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If rsDetail.Status = (adRecNew) Or rsDetail.Status = (adRecModified) Then
            If IsNull(rsDetail!cItemNo) Then
                rsDetail.Delete
            ElseIf Trim(rsDetail!cItemNo) = "" Then
                rsDetail.Delete
            Else
                rsDetail.MoveNext
            End If
        Else
            rsDetail.MoveNext
        End If
    Loop

    GetChild

    If rsDetail.RecordCount < 1 Then
        MsgBox "Cannot save transaction without details.", vbExclamation, "ComUnion"
        MandatoryOK = False
        Exit Function
    End If

End Function

'Filter detail recordset to header's primary
Private Sub GetChild()
    rsDetail.Filter = "cPRNo = '" & Trim(rsHeader!cPRNo) & "'"
End Sub

'Sets the form if record number is zero
Private Sub RSZero()
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    sbRS.Panels(4) = ""
    sbRS.Panels(5) = ""
    
    Set dtgPR.DataSource = Nothing
    dtgPR.Refresh
    
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    If rsDetail.State = adStateOpen Then rsDetail.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    
    txtPRNo.Locked = False
    txtPRNo.SetFocus
    
    Mode = Find
    
End Sub

Sub SearchObj(lEnable As Boolean)
    dtbDate.Enabled = lEnable
    cboType.Enabled = lEnable
    cmdPickSO.Enabled = lEnable
    dtbNeeded.Enabled = lEnable
    cmdPickEmpCode.Enabled = lEnable
    cmdPickDeptID.Enabled = lEnable
End Sub


'Gets initital item values
Private Sub GetInitialItemValues(RefRS As Recordset)
    RefRS!cItemType = "Trade"
    RefRS!cDesc = Trim(GetValueFrTable("cDesc", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!cUnit = Trim(GetValueFrTable("cPrimaryUnit", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
End Sub

'Gets initital asset values
Private Sub GetInitialAssetValues(RefRS As Recordset)
    RefRS!cItemType = "Asset"
    RefRS!cDesc = Trim(GetValueFrTable("cDesc", "ASSET", "cAssetNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!cUnit = "Unit"
End Sub

'Gets initital asset values
Private Sub GetInitialSupplyValues(RefRS As Recordset)
    RefRS!cItemType = "Supply"
    RefRS!cDesc = Trim(GetValueFrTable("cDesc", "SUPPLY", "cSupplyNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!cUnit = Trim(GetValueFrTable("cUnit", "SUPPLY", "cSupplyNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
End Sub

Private Function GetSearchString() As String
On Error GoTo ErrorHandler
Dim sWhere As String

    GetSearchString = True

    If Trim$(txtPRNo.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cPRNo LIKE '" & Trim$(txtPRNo.Text) & "%'"
    End If

    If Trim$(dtbDate.Text) <> "__/__/____" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " dDate = '" & Trim$(dtbDate.Text) & "'"
    End If
    
    If Trim$(txtType.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cType LIKE '" & Trim$(txtType.Text) & "%'"
    End If
    
    If Trim$(txtRefNo.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cRefNo LIKE '" & Trim$(txtRefNo.Text) & "%'"
    End If
    
    If Trim$(dtbNeeded.Text) <> "__/__/____" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " dNeeded = '" & Trim$(dtbNeeded.Text) & "'"
    End If
    
    If Trim$(txtRequestedBy.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cRequestedBy LIKE '" & Trim$(txtRequestedBy.Text) & "%'"
    End If
    
    If Trim$(txtDepartment.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cDepartment LIKE '" & Trim$(txtDepartment.Text) & "%'"
    End If
        
    GetSearchString = Trim$(sWhere)

    Exit Function
ErrorHandler:
    GetSearchString = "ERROR"
End Function

Private Sub txtRemarks_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then TBNewLine
End Sub

Private Sub txtDepartment_Change()
    txtDeptDesc = ""
    txtDeptDesc = GetValueFrTable("Description", "SEC_DEPARTMENT", "DeptID = '" & Trim(txtDepartment) & "'", True)
End Sub

Private Sub txtDepartment_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtDeptDesc) = "" And Trim(txtDepartment) <> "" Then cmdPickDeptID_Click
End Sub

Private Sub txtRequestedBy_Change()
    txtEmpName = ""
    txtEmpName = GetValueFrTable("cEmpName", "EMPLOYEE", "cEmpCode = '" & Trim(txtRequestedBy) & "'")
    If txtEmpName = "" Then
        If Mode = AddNewEdit Then GetUser txtRequestedTo, txtEmpName
    End If
End Sub

Private Sub txtRequestedBy_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtEmpName) = "" And Trim(txtRequestedBy) <> "" Then cmdPickEmpCode_Click
End Sub

Private Sub txtRequestedTo_Change()
    txtRequestedToName = ""
    txtRequestedToName = GetValueFrTable("cEmpName", "EMPLOYEE", "cEmpCode = '" & Trim(txtRequestedTo) & "'")
    If txtRequestedToName = "" Then
        If Mode = AddNewEdit Then GetUser txtRequestedBy, txtRequestedToName
    End If
End Sub

Private Sub txtType_Change()
    If Trim(txtType) <> "" Or txtType <> vbNullString Then
        cboType = Trim(txtType)
    Else
        cboType.ListIndex = -1
    End If
End Sub

'Form list to grid
Public Sub AddDetailsFromList()
    
    GetChild
    
    If Trim(cboType) = "From SO" Then
        If rsDetail.RecordCount <> 0 Then
            rsDetail.MoveFirst
            Do Until rsDetail.RecordCount = 0
                rsDetail.Delete adAffectCurrent
                If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
            Loop
        End If
    End If
    
    With frmARDRList.lvwList
        For i = 1 To .ListItems.Count
            If .ListItems(i).Checked = True Then
                rsDetail.AddNew
                rsDetail!cCompanyID = COID
                rsDetail!cPRNo = Trim(rsHeader!cPRNo)
                rsHeader!cRefNo = Trim(frmARDRList.mRefPK)
                rsDetail!cType = "Existing"
                rsDetail!cItemType = "Trade"
                rsDetail!cItemNo = Trim(.ListItems(i).Text)
                rsDetail!cDesc = Trim(.ListItems(i).SubItems(1))
                rsDetail!cUnit = Trim(.ListItems(i).SubItems(3))
                rsDetail!nQty = CDbl(.ListItems(i).SubItems(4))
                rsDetail!nRefIdentity = CDbl(.ListItems(i).SubItems(7))
                rsDetail!nFactor = CDbl(.ListItems(i).SubItems(8))
                If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'ITM_MAN_BARCODE'") = True Then
                    rsDetail!cBarcodeID = CDbl(.ListItems(i).SubItems(9))
                End If
                
                If Trim(cboType) = "From RS" Then
                    rsDetail!cItemType = GetValueFrTable("cItemType", "REQUISITIONSLIP_T", "cTranNo = '" & rsHeader!cRefNo & "' AND nIdentity = " & rsDetail!nRefIdentity & " ")
                    rsHeader!cRequestedBy = GetValueFrTable("cEmpCode", "REQUISITIONSLIP", "cTranNo = '" & rsHeader!cRefNo & "' ")
                    rsHeader!cDepartment = GetValueFrTable("DeptID", "REQUISITIONSLIP", "cTranNo = '" & rsHeader!cRefNo & "' ")
                End If
            End If
        Next i
    End With

    GetChild

End Sub

Private Sub txtLongDesc_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txtLongDesc_LostFocus()
    txtLongDesc.Visible = False
    dtgPR.Col = 5
    dtgPR.SetFocus
End Sub

'Change Transaction Number
Sub ChangeTranNo(strTranNo As String)
    GetChild
    
    rsHeader!cPRNo = strTranNo
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        rsDetail!cPRNo = strTranNo
        rsDetail.MoveNext
    Loop
    
    GetChild
End Sub

'Clear Data Grid
Private Sub ClearDataGrid()
    GetChild
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.RecordCount = 0
            rsDetail.Delete adAffectCurrent
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Loop
    End If
    GetChild
End Sub

Private Sub ClearDetails()
    txtRefNo = Empty
    dtbNeeded.Text = "__/__/____"
    txtRequestedBy = Empty
    txtDepartment = Empty
    txtRemarks = Empty
    ClearDataGrid
End Sub

Public Sub ShowTran()
    If Mode = Find Then

        OpenNewConnection connHeader
        OpenNewConnection connDetail

        Set rsHeader = Nothing
        Set rsDetail = Nothing
        Set rsHeader = New ADODB.Recordset
        Set rsDetail = New ADODB.Recordset

        OpenRecordsetWithCN rsDetail, "*", "REQUISITION_T", connDetail, "WHERE cPRNo = '" & Trim(txtPRNo) & "'", True
        OpenRecordsetWithCN rsHeader, "*", "REQUISITION", connHeader, "WHERE cPRNo = '" & Trim(txtPRNo) & "'", True

        Set FrmName = Me
        FormLocking True

        If rsHeader.RecordCount = 0 Then
            FormWaitHide
            MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
            RSZero
            FormSearch True
            SearchObj True
            Mode = Find
            Exit Sub
        End If
            SetDataSource
            SetDataField
            txtPRNo.BackColor = &HE0FFFF
            Mode = Normal
            BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , True, , , , True, , , True
'            BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , lACPost, lACCancel, , , True, True, lACPrint, True

    End If
End Sub



Private Sub SetVisibleEnable()

    txtRequestedTo.Visible = GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_REQUESTEDTO'")
    txtRequestedToName.Visible = GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_REQUESTEDTO'")
    cmdPickRequestedTo.Visible = GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_REQUESTEDTO'")
    
    txtRToDept.Visible = GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_REQUESTEDTO'")
    txtRToDeptName.Visible = GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_REQUESTEDTO'")
    cmdPickRToDept.Visible = GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_REQUESTEDTO'")
    
    txtBranch.Visible = GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_BRANCH'")
    txtBranchName.Visible = GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_BRANCH'")
    cmdPickBranch.Visible = GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_BRANCH'")

    dtgPR.Columns("Balance").Visible = GetValueFrTable("lBit", "system_option", "cCode = 'ITM_VIS_BALANCE'")
    dtgPR.Columns("Consumed").Visible = GetValueFrTable("lBit", "system_option", "cCode = 'ITM_VIS_CONSUMED'")
    dtgPR.Columns("Last Ordered").Visible = GetValueFrTable("lBit", "system_option", "cCode = 'ITM_VIS_LASTORDERED'")
    dtgPR.Columns("Quantity Approved").Visible = GetValueFrTable("lBit", "system_option", "cCode = 'ITM_VIS_QTYAPPROVED'")

    If GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_BRANCH'") = False And _
            GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_REQUESTEDTO'") = True Then
        
        txtPurpose.Top = txtBranch.Top
        cboPurpose.Top = txtBranchName.Top
        txtRemarks.Top = txtPurpose.Top
    
     ElseIf GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_BRANCH'") = True And _
            GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_REQUESTEDTO'") = False Then
        
        txtRemarks.Top = txtBranch.Top
        txtBranch.Top = txtRequestedTo.Top
        txtBranchName.Top = txtRequestedTo.Top
        cmdPickBranch.Top = txtRequestedTo.Top
        txtPurpose.Top = txtRToDept.Top
        cboPurpose.Top = txtRToDept.Top
        
        
        SSTab1.Height = 7435
        ComunionFrames1.Height = 3030
        ComunionFrames2.Top = 7669
        
    ElseIf GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_BRANCH'") = False And _
            GetValueFrTable("lBit", "system_option", "cCode = 'CLNT_OPT_REQUESTEDTO'") = False Then
            
        txtPurpose.Top = txtRequestedTo.Top
        cboPurpose.Top = txtRequestedToName.Top
        txtRemarks.Top = txtRToDept.Top
        
        SSTab1.Height = 6635
        ComunionFrames1.Height = 2670
        ComunionFrames2.Top = 6870
    End If
    
End Sub

Private Function GetBalance() As Boolean
Dim rsBalance As New Recordset

    If Mode <> AddNewEdit Then Exit Function
    
    If Trim(rsDetail!cItemType) = "Supply" Then
        sSQL = "SELECT *, ISNULL((nInitial - nOutgoing + nIncoming + nAdjustment), 0) AS nBalance " & _
                " FROM V_SuppliesBalanceInquiry_Module WHERE cSupplyNo = '" & rsDetail!cItemNo & "' AND cCompanyID = '" & COID & "'"
        rsBalance.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    ElseIf Trim(rsDetail!cItemType) = "Trade" Then
        If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'ITM_MAN_USEPARTNO'") = False Then
            ProductBalanceCommand rsBalance, rsDetail!cItemNo
        Else
            sSQL = "exec sp_ProductBalanceInquiry_ModuleWPartNo '" & rsDetail!cItemNo & "', '" & rsDetail!cBarcodeID & "', '" & COID & "'"
            rsBalance.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
        End If
    End If
'    rsBalance.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    
    If rsBalance.RecordCount <> 0 Then
        rsDetail!nBalance = rsBalance!nBalance
        GetBalance = True
    Else
        GetBalance = False
        rsDetail!nConsumed = 0
        Set rsBalance = Nothing
        Exit Function
    End If
    
    Set rsBalance = Nothing

End Function

Private Function GetConsumed() As Boolean
Dim rs As New ADODB.Recordset


    If Mode <> AddNewEdit Then Exit Function
    If Trim(rsDetail!cItemType) = "Supply" Then
        If IsNull(rsDetail!dlastOrdered) = True Then
            sSQL = "SELECT SUM(nOutgoing) as nConsumed FROM V_SuppliesBalanceInquiry_Module where cCompanyID = '" & COID & "'" _
                    & " AND cSupplyNo = '" & Trim(rsDetail!cItemNo) & "'"
        
        Else
            sSQL = "SELECT SUM(nOutgoing) as nConsumed FROM V_SuppliesBalanceInquiry_Module where cCompanyID = '" & COID & "'" _
                    & " AND cSupplyNo = '" & Trim(rsDetail!cItemNo) & "' and dDate > '" & rsDetail!dlastOrdered & "'"
        End If
    ElseIf Trim(rsDetail!cItemType) = "Trade" Then
        If IsNull(rsDetail!dlastOrdered) = True Then
            sSQL = "SELECT SUM(nIssues) as nConsumed FROM V_ProductBalanceInquiry_ModuleWPartNo where cCompanyID = '" & COID & "'" _
                    & " AND cItemNo = '" & Trim(rsDetail!cItemNo) & "' and cBarcodeID = '" & rsDetail!cBarcodeID & "'"
        
        Else
            sSQL = "SELECT SUM(nOutgoing) as nConsumed FROM V_ProductBalanceInquiry_ModuleWPartNo where cCompanyID = '" & COID & "'" _
                    & " AND cItemNo = '" & Trim(rsDetail!cItemNo) & "' and cBarcodeID = '" & rsDetail!cBarcodeID & "' and dDate > '" & rsDetail!dlastOrdered & "'"
        End If
    End If
    Set rs = New ADODB.Recordset
    rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    
    If rs.RecordCount <> 0 Then
        rsDetail!nConsumed = rs!nConsumed
        GetConsumed = True
    Else
        GetConsumed = False
        rsDetail!nConsumed = 0
        Set rs = Nothing
        Exit Function
    End If
    
    Set rs = Nothing
End Function

Private Function GetLastOrderd() As Boolean
Dim rs As New ADODB.Recordset

    If Mode <> AddNewEdit Then Exit Function
    sSQL = "SELECT * FROM po_t a LEFT OUTER JOIN po b ON b.cCompanyID = a.cCompanyID AND b.cPONo = a.cPONo" _
            & " WHERE a.cItemNo = '" & rsDetail!cItemNo & "' AND isnull(a.cBarcodeID,'') = '" & rsDetail!cBarcodeID & "'" _
            & " ORDER BY b.dDate ASC"

    Set rs = New ADODB.Recordset
    rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    
    If rs.RecordCount <> 0 Then
        rs.MoveLast
        rsDetail!dlastOrdered = rs!dDate
        GetLastOrderd = True
    Else
        GetLastOrderd = False
        Set rs = Nothing
        Exit Function
    End If
    
    Set rs = Nothing

End Function
